#
# @lc app=leetcode.cn id=516 lang=python3
#
# [516] 最长回文子序列
#

# @lc code=start
class Solution:
    def longestPalindromeSubseq(self, s: str) -> int:
        s1 = s
        s2 = s[::-1]
        
    

        def longestPublicChildSubSer(s1: str, s2: str) -> int:
            m = len(s1)
            n = len(s2)
            dp = [[0 for i in range(n)] for j in range(m)]
            if s1[0] == s2[0]:
                dp[0][0] = 1
            for i in range(1, m):
                if s1[i] == s2[0]:
                    dp[i][0] = 1
                else:
                    dp[i][0] = max(dp[i-1][0], dp[i][0])
            for i in range(1, n):
                if s2[i] == s1[0]:
                    dp[0][i] = 1
                else:
                    dp[0][i] = max(dp[0][i-1], dp[0][i])
            for i in range(1, m, 1):
                for j in range(1, n, 1):
                    if s1[i] == s2[j]:
                        dp[i][j] = dp[i-1][j-1] + 1
                    else:
                        dp[i][j] = max(dp[i-1][j], dp[i][j-1])
            return dp[m-1][n-1]
        return longestPublicChildSubSer(s1, s2)       
# @lc code=end

